layui.use(['laydate','form','table','laytpl','layer'], function(){
	var laydate = layui.laydate;
	var form = layui.form;
	var table = layui.table;
	var laytpl = layui.laytpl;
	var layer = layui.layer;
	layui.cate = [1,2,3];//采购支出分类集合
	/*@时间*/
	laydate.render({
	  	elem: '#start' //指定元素
	});
	laydate.render({
	  	elem: '#end' //指定元素
	});
	let ty = $('input[name="ty"]').val()
	/*@初始化table*/
	layui.tableObj = table.render({
	    elem: '#table-list',
	    id: 'list',
	    url: '/finance/cate/index/ty/'+ty, //数据接口
	    page: false, //开启分页
	    cols: [[ //表头
	    	{type: 'checkbox'},
	    	{field: 'cat_name', title: '分类名称'},
	    	{title: '操作', toolbar: '#table-btn'}
	    ]],
	});
	
	/*@删除请求*/
	del = function(obj_data){
		$.post('/finance/cate/del', obj_data, function(data){
			if(data.code !== 1){
				layer.msg(data.msg, {icon: 5})
			}else{
				layer.msg(data.msg, {icon: 6, time: 1000}, function(){
					parent.location.reload()
				})
			}
		})
	}
	/*@批量删除*/
	del_all = function(){
		var checkStatus = table.checkStatus('list')
	    var data = checkStatus.data;
	    if(data.length == 0){
	    	layer.msg('请选中要删除的数据',{icon: 5})
	    	return
	    }
	    layer.confirm('确定删除', {icon: 3, title:'提示'}, function(){
	    	let obj = {}
		    obj.id = []
		    for(var i = 0;i < data.length;++i){
		    	if($.inArray(Number(data[i].expend_cate_id), layui.cate) == -1){
		    		obj.id.push(data[i].expend_cate_id)
		    	}
		    }
		    del(obj)
	    })
	    
	}
	/*@监听工具*/
	table.on('tool(list)', function(obj_tr){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	  	var data = obj_tr.data; //获得当前行数据
	  	var layEvent = obj_tr.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
	  	var tr = obj_tr.tr; //获得当前行 tr 的DOM对象
	  	if(layEvent === 'del'){ //删除
	  		layer.confirm('确定删除', {icon: 3, title:'提示'}, function(){
	  			let obj_data = {}
		  		obj_data.id = data.expend_cate_id
		  		del(obj_data)
	  		})
	  	}
	});
});